package com.example.widget.custom;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.widget.R;

public class StayView extends View {
    private int textSize;
    private String text;
    private int textColor;

    private Paint paint;
    private Paint arcPaint;
    public StayView(Context context){
        super(context);
    }
    public StayView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.StayView);
        textSize = typedArray.getInt(R.styleable.StayView_textSize, 40);
        text = typedArray.getString(R.styleable.StayView_text);
        textColor = typedArray.getColor(R.styleable.StayView_textColor, Color.parseColor("#F8130B"));
        init();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    }

    private void init() {
        paint = new Paint();
        paint.setStrokeWidth(9);
        paint.setTextSize(textSize);
        paint.setAntiAlias(true);
        paint.setColor(textColor);
        paint.setStyle(Paint.Style.FILL);

        arcPaint = new Paint();
        arcPaint.setStrokeWidth(5);
        arcPaint.setTextSize(15);
        arcPaint.setColor(Color.parseColor("#E8E8E8"));
        arcPaint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        RectF rectF = new RectF(0, 0, 100, 100);
        canvas.drawArc(rectF,0,360,false,arcPaint);
        canvas.drawText(text,rectF.centerX()-17,rectF.centerY()+15,paint);
    }

    public int getTextSize() {
        return textSize;
    }

    public void setTextSize(int textSize) {
        this.textSize = textSize;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public int getTextColor() {
        return textColor;
    }

    public void setTextColor(int textColor) {
        this.textColor = textColor;
    }
}
